﻿using BySoft.Server.Business;
using BySoft.Server.Common.Entity;
using BySoft.Server.Common.Enum;
using BySoft.Server.Consts;
using BySoft.Web.Utility;
using OneSoft.EntityCore;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BySoft.Web.Site.MasteData
{
    public partial class KnifeTypeAdd : AuthBasePage
    {
        public string sequenceName
        {
            get { return "MD_KnifeType"; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //txtKnifeTypeID.Attributes.Add("readonly", "true");
               
            }
            Master.ValidationGroup = "gSubmit";
        }

      


      
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(CurrentUser.UserID))
                {
                    UIHelper.AlertMessage(this.Page, "等待时间太久，请重新填写刀具类型资料！");
                    return;
                }
                if (!string.IsNullOrEmpty(this.txtKnifeTypeID.Text.Trim()))
                {
                    if ((new MdKnifetype()).IsIDExists(txtKnifeTypeID.Text.Trim()))
                    {
                        UIHelper.AlertMessage(this.Page, "刀具类型编号已存在，请重新填写！");
                        return;
                    }
                    if ((new MdKnifetype()).IsNameExists(this.txtKnifeTypeName.Text.Trim(),""))
                    {
                        UIHelper.AlertMessage(this.Page, "刀具类型名称已存在，请重新填写！");
                        return;
                    }
                    MdKnifetypeEntity Knife = new MdKnifetypeEntity();
                    Knife.KnifeTypeID = this.txtKnifeTypeID.Text.Trim();
                    Knife.KnifeTypeName = this.txtKnifeTypeName.Text.Trim();
                
                    Knife.Status = "1";
                    Knife.CreateDate = DateTime.Now;
                    Knife.CreateUserID = CurrentUser.UserID;
                    Knife.CreateUserName = CurrentUser.UserName;

                    if (MdKnifetype.InsertMdKnifetype(Knife))
                    {
                        base.LogAction(BaseEnum.ActionType.Add, Knife.KnifeTypeID, true, null, new EntityBase[] { Knife });
                        UIHelper.AlertMessageGoToURL(this.Page, Message.SaveSuccess, "../MasteData/KnifeTypeList.aspx");
                    }
                    else
                    {
                        UIHelper.AlertMessage(this.Page, Message.SaveFail);
                    }
                }

            }
            catch (Exception ex)
            {
                UIHelper.AlertMessage(this.Page, FomatString(ex.Message.ToString()));
            }
        }
    }
}